package com.techyuan.algorithm.others;

import java.util.Arrays;

/**
 * 题目位置：2.1-4
 * Created by tianjuntao on 2016/9/5.
 */
public class ArrSum {
    public static void main(String[] args) {
        int[] sumArr = arrSum(new int[]{1, 2, 3, 4, 5}, new int[]{2, 3, 7, 3, 4});
        System.out.println(Arrays.toString(sumArr));
    }

    public static int[] arrSum(int[] a, int[] b) {
        int[] sumArr = new int[a.length + 1];
        int tmp = 0;
        for (int i = 0; i < a.length; i++) {
            int iSum = a[i] + b[i] + tmp;
            if (iSum < 10) {
                sumArr[i] = iSum;
                tmp = 0;
            } else {
                sumArr[i] = iSum - 10;
                tmp = 1;
            }
        }
        return sumArr;
    }
}
